//
//  ViewController.m
//  2017classone
//
//  Created by M on 17/2/21.
//  Copyright © 2017年 apple1512. All rights reserved.
//

#import "ViewController.h"

@interface ViewController () <UIPickerViewDataSource,UIPickerViewDelegate>
//遵守协议
@property (nonatomic,strong)UIPickerView * pickerView;//自定义pickerview
@property (nonatomic,strong)NSArray * letter;//保存要展示的字母
@property (nonatomic,strong)NSArray * letter2;
@property (nonatomic,strong)NSArray * number;//保存要展示的数字

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //获取需要展示的数据
    [self loadData];
    
    // 初始化pickerView
    self.pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, 200)];
    [self.view addSubview:self.pickerView];
    
    //指定数据源和委托
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    
//    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
//    [center addObserver:self selector:@selector(onNoti) name:nil object:nil];
//    [center removeObserver:self];
    
    
    
}



#pragma mark 加载数据
-(void)loadData
 {
    //需要展示的数据以数组的形式保存
    self.letter = @[@"冯鹏",@"冯鹏",@"冯鹏",@"冯鹏"];
    self.letter2 = @[@"邓星辰",@"邓星辰",@"邓星辰",@"邓星辰"];
    self.number = @[@"傻子",@"傻子",@"傻子",@"傻子"];
}

#pragma mark UIPickerView DataSource Method 数据源方法

//指定pickerview有几个表盘
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 3;//第一个展示字母、第二个展示数字
}

//指定每个表盘上有几行数据
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    NSInteger result = 0;
    switch (component) {
        case 0:
            result = self.letter.count;//根 据数组的元素个数返回几行数据
            break;
        case 1:
            result = self.letter2.count;
        case 2:
            result = self.number.count;
            break;
            
        default:
            break;
    }
    
    return result;
}

#pragma mark UIPickerView Delegate Method 代理方法

//指定每行如何展示数据（此处和tableview类似）
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString * title = nil;
    switch (component) {
        case 0:
            title = self.letter[row];
            break;
        case 1:
            title = self.letter2[row];
            break;
        case 2:
            title = self.number[row];
           break;
        default:
            break;
    }
    
    return title;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
